<template>
  <div class="photoinfo-container">
      <h3>{{photoInfo.title}} </h3>
    <div class="subtitle">
        <span>发表时间：{{photoInfo.add_time | dateFormat}}</span>
        <span>点击：{{photoInfo.click}}次</span>
    </div>
    <hr>
    <!-- 缩略图区域 -->
    <!-- <img class="preview-img" v-for="(index, item) in list" :key="item.src" :src="item.src" height="100" @click="$preview.open(index, list)"> -->
     <vue-preview :slides="list"></vue-preview>
    <!-- 图片内容区域 -->
    <div class="content" v-html="photoInfo.content">

    </div>
    <!-- 放置现成的评论子组件 -->
    <cmt-box :commentsId="id"></cmt-box>
  </div>
</template>

<script>
// 导入评论子组件
import comment from '../subcomponents/comments.vue';
export default {

  data () {
    return {
        id:this.$route.params.id, // 获取地址栏的id
        photoInfo:{},
        list:[],
    }
  },

  methods: {
      getPhotoInfo(){
          this.$http.get("http://www.liulongbin.top:3005/api/getimageInfo/"+this.id).then(result=>{
              console.log(result.body);
              
              if(result.body.status == 0){
                  this.photoInfo = result.body.message[0];
              }
          })
      },
      // 获取缩略图
      getThumbs(){
          this.$http.get('http://www.liulongbin.top:3005/api/getthumimages/' + this.id).then(result=>{
              if(result.body.status == 0){
                  result.body.message.forEach(item=>{
                      item.w = 600;
                      item.h = 400;
                      item.msrc = item.src;
                  });
                  // 把完整的数据保存到list中
                  this.list = result.body.message;
              }
          })
      }
  },

  created () {
      this.getPhotoInfo();
      this.getThumbs();
  },
  components: {
      "cmt-box":comment,
  }
}
</script>

<style lang='less'>
.photoinfo-container{
    padding: 3px;
    h3{
        color: #26A2ff;
        font-size: 15px;
        text-align: center;
        margin: 15px 0;
    }
    .subtitle{
        display: flex;
        justify-content: space-between;
        font-size: 13px;
    }
    .content{
        line-height: 30px;
        font-size: 13px;
    }
}
</style>
